package com.situ.science.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.situ.science.mapper.ContestMapper;
import com.situ.science.pojo.Contest;
import com.situ.science.pojo.charts.ContestNum;
import com.situ.science.pojo.query.ContestQuery;
import com.situ.science.pojo.vo.ProjectVo;
import com.situ.science.service.IContestService;
import com.situ.science.utils.PageRusults;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ContestServiceImpl implements IContestService {
    @Autowired
    private ContestMapper contestMapper;
    @Override
    public List<Contest> list() {
        return contestMapper.list();
    }

    @Override
    public PageRusults selectByPage(ContestQuery contestQuery) {
        int limit = contestQuery.getLimit()!= null? contestQuery.getLimit() : 10; // 设置默认值为 10，如果 limit 为 null
        int page = contestQuery.getPage()!= null? contestQuery.getPage() : 1;

        PageHelper.startPage(page, limit);
        //1.查询当前页列表
        List<Contest> contests = contestMapper.selectByPage(contestQuery);
        //2.用一个小插件查询总数量
        PageInfo pageInfo = new PageInfo(contests);
        int total = (int) pageInfo.getTotal();
        return new PageRusults(0,"",total,contests);
    }

    @Override
    public void add(Contest contest) {
        contestMapper.add(contest);
    }

    @Override
    public List<ContestNum> contestNum() {
        return contestMapper.contestNum();
    }

    @Override
    public Contest getById(Integer id) {
        return contestMapper.getById(id);
    }
}
